/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.IO;

import java.io.File;

/**
 *
 * @author kylin
 */
public class TestFileIterator {
    
    public static void main(String args[]){
        String path="/home/kylin/Shared/KGFileuploader1.0";
        DirectoryIterator i=new DirectoryIterator();
        i.start(path);
    }
}
class DirectoryIterator{
    File files[]=null;
    public DirectoryIterator(){}
    
    public void start(String path){
        File file=new File(path);
        if(!file.isDirectory()){
            System.out.println("file path must be a directory");
        }else{
            files=file.listFiles();
            
            for(int i=0;i<files.length;i++){
                File sub=files[i];
                
                if(sub.isDirectory()){
                    System.out.println(sub.getAbsoluteFile());
                    iterator(sub.getAbsolutePath());
                }else{
                    System.out.println(sub.getName());
                }
            }
        }
    }
    
    public void iterator(String path){
        File file=new File(path);
        File files[]=file.listFiles();
        for(int i=0;i<files.length;i++){
            if(files[i].isDirectory()){
                System.out.println(files[i].getAbsolutePath());
                iterator(files[i].getAbsolutePath());
            }else{
                System.out.println(files[i].getName());
            }
        }
    }
}
